import { serverUrl, getRequest, postRequestForm } from '@/utils/request';

/**
 * @param 个人中心相关接口
 */
export const getUserCenter = () => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/userCenter', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param 优惠劵相关接口
 */
export const getCouponsList = () => {
  return new Promise((resolve, reject) => {
    postRequestForm('app/wechatMini/ucenter/coupon/list', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param 获取钱包数据
 */
export const getWalletInfo = () => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/wallet', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param 用户提现
 */
export const withdrawDeposit = () => {
  return new Promise((resolve, reject) => {
    getRequest('app/security/withdraw', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 获取押金记录列表
 */
export const getDepositOrderList = () => {
  return new Promise((resolve, reject) => {
    postRequestForm('app/wechatMini/security/orderList', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {orderId} 通过id查询押金详情
 *
 */
export const getDepositDetail = (orderId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/securityOrderDetail', { orderId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * 查询是否是本品牌机柜
 * @param {Object} obj - 包含设备ID的对象
 */
export const getFaultReport = (deviceId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/rentbox', deviceId, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 获取优惠券
 */
export const getObtainCouponsList = (deviceId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/ucenter/obtainCoupons', { deviceId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 请求广告轮播图
 */
export const requestCarouselListData = (deviceId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/site/advert', { deviceId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 检查是否已经有租借过的订单
 */
export const hasRentOrder = () => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/hasRentOrder', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * 查询柜机是否可租借充电宝
 * @param {string} deviceId - 设备ID
 */
export const isUnoccupiedPowerBank = (deviceId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/check', { deviceId }, (res) => {
      resolve(res);
    });
  });
};


/**
 * 微信
 * @param {string} 判断是否有押金
 */

export const isFinishDepositWx = () => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/hasSecurityOrder', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * 支付宝
 * @param {string} 判断是否有押金
 */
export const isFinishDepositAli = () => {
  return new Promise((resolve, reject) => {
    getRequest('app/aliMini/hasSecurityOrder', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * 查询服务器配置的支付渠道是否支持微信免押，支持则优先微信免押，不支持则使用微信普通支付,并统一下单
 * @param {string} 判断是否有押金
 */
export const isFinishPrepay = () => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/prepay', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * 查询微信免押状态
 * @param {string} deviceId - 设备ID
 */
export const isrentboxShow = (params) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/rentboxShow', params, (res) => {
      resolve(res);
    });
  });
};

/**
 * 微信免押支付的数据，去唤起微信支付页面
 * @param {string} deviceId - 设备ID
 */
export const isWechatPowerBank = (deviceId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/createWechatMiniFee', deviceId, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 获取查询订单
 */
export const checkPayIsValid = (orderUuid) => {
  return new Promise((resolve, reject) => {
    getRequest('app/security/pay/check', { orderUuid }, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 获取广告信息
 */
export const getAdvert = () => {
  return new Promise((resolve, reject) => {
    getRequest('api/advert/rentbox/distribute/list', { position: 'site_list' }, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 获取网点列表
 */
export const getSiteList = (queryParam) => {
  return new Promise((resolve, reject) => {
    postRequestForm('app/wechatMini/siteList', queryParam, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 获取某位置附近网点
 */

export const getNearbySite = (queryParam) => {
  return new Promise((resolve, reject) => {
    postRequestForm('/app/site/around/list', queryParam, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 提交form表单
 */

export const saveQuestion = (data) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/question/save', data, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 上传图片
 */

export const getAliyunConfig = () => {
  return new Promise((resolve, reject) => {
    getRequest('api/aliyunconfig', {}, (res) => {
      resolve(res);
    });
  });
};

/**
 * 正在弹宝
 * @param {Object} obj - 包含设备ID和优惠券记录ID的对象
 */
export const popupPowerBank = (deviceId, couponRecoreId = 0) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/popup', { deviceId, couponRecoreId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {params}  查询白名单,页面扫码加载
 */
export const getWhitelistDetail = (params) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/whitelist', params, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {params} 添加白名单
 */
export const obtainWhitelist = (params) => {
  return new Promise((resolve, reject) => {
    getRequest('app/whiteist/record/users/obtain', params, (res) => {
      resolve(res);
    });
  });
};

// /**
//  * @param {params} url中间页过渡
//  */
// export const getRequestUrl = (id) => {
//   return new Promise((resolve, reject) => {
//     getRequest('app/whiteist/record/users/obtain', { id }, (res) => {
//       resolve(res);
//     });
//   });
// };

/**
 * @param {orderId}
 */
export const payBePaidOrder = (orderId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/order/pay/security', { orderId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {orderId} 获取订单数据
 */
export const getBePaidOrderDeatil = (orderId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/order/pay', { orderId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {orderId}
 */
export const payByWechatFee = (orderId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/order/pay/wechatFee', { orderId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * 弹宝失败
 * @param {string} orderId - 订单ID
 */
export const checkPopup = (orderId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/order/checkPopup', { orderId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * 重新弹宝
 * @param {string} orderId - 订单ID
 */
export const checkOrderis = (orderId,deviceId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/order/check', { orderId,deviceId }, (res) => {
      resolve(res);
    });
  });
};


/**
 * @param {orderId} 通过id查询订单详情
 */
export const getRentOrderDetail = (orderId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/rentOrderDetail', { orderId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * @param {string} 查询订单列表
 */
export const getOrderList = (params) => {
  return new Promise((resolve, reject) => {
    postRequestForm(
      'app/wechatMini/orderList',
      params,
      (res) => {
        resolve(res);
      },
      '/pages/order/order'
    );
  });
};

/**
 * 网络异常
 * @param {string} orderId - 订单ID
 */
export const getcheckPopup = (orderId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/wechatmin/order/checkPopup', { orderId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * 购买订单
 * @param {string} orderId - 订单ID
 */
export const buyOrder = (orderId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/rentbox/order/buy', { orderId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * 获取优惠券详情
 * @param {string} couponId - 优惠券ID
 */
export const getCouponDetail = (couponId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/wechatMini/coupon', { couponId }, (res) => {
      resolve(res);
    });
  });
};

/**
 * 领取优惠券
 * @param {string} couponId - 优惠券ID
 */
export const receiveCoupon = (couponId) => {
  return new Promise((resolve, reject) => {
    getRequest('app/coupon/record/users/obtain', { couponId }, (res) => {
      resolve(res);
    });
  });
};
